package com.byq.mm.abstractx.protocol;

import com.byq.mm.abstractx.device.Device;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;



public class Defination implements Serializable{
//	static public final String ATTRBUTE_NAME_FROM = "from";
//	static public final String ATTRBUTE_NAME_to = "to";
	static public class OfferAction{
		static public final String ACTION_NAME = "offer";
	}
	static public class ReplyAction{
		static public final String ACTION_NAME = "reply";
		static public final String REPLY_ACCEPT = "accept";
		static public final String REPLY_REJECT = "reject";
	}
	static public class RequestAction{
		static public final String ACTION_NAME = "request";
	}
	static public class ResponseAction{
		static public final String ACTION_NAME = "response";
		static public final String RESPONSE_REFUSE = "refuse";
	}

	
	String from;
	String to;
	String action;
	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	Map<String, String> attributes =new HashMap<String, String>();
	public Map<String, String> getAttributes() {
		return attributes;
	}

	Device device;

	public Device getDevice() {
		return device;
	}

	public void setDevice(Device device) {
		this.device = device;
	}
	public void offer(Device d){
		action = OfferAction.ACTION_NAME;
		device = d;
		
	}
	public boolean isOffer(){
		return 	action.equals(OfferAction.ACTION_NAME);
	}
	public void accept(Device d){
		action = ReplyAction.ACTION_NAME;
		attributes.put(ReplyAction.ACTION_NAME, ReplyAction.REPLY_ACCEPT);
		device = d;
		
	}
	public boolean isAccept(){
		return action.equals(ReplyAction.ACTION_NAME)

		&&
		attributes.get(ReplyAction.ACTION_NAME).equals(ReplyAction.REPLY_ACCEPT);

	}
	public void reject(){
		action = ReplyAction.ACTION_NAME;
		attributes.put(ReplyAction.ACTION_NAME, ReplyAction.REPLY_REJECT);
		
	
	}
	public boolean isReject(){
		
		return action.equals(ReplyAction.ACTION_NAME)&&
		attributes.get(ReplyAction.ACTION_NAME).equals(ReplyAction.REPLY_REJECT);
		
		
	}
	
	
	
	public void request(){
		action = RequestAction.ACTION_NAME;
	}
	public boolean isRequest(){
		return action.equals(RequestAction.ACTION_NAME);
	}
	public void refuse(){
		action = ResponseAction.ACTION_NAME;
		attributes.put(ResponseAction.ACTION_NAME, ResponseAction.RESPONSE_REFUSE);
		
	}
	public boolean isRefuse(){
		return action.equals(ResponseAction.ACTION_NAME)&&
		attributes.get(ResponseAction.ACTION_NAME).equals(ResponseAction.RESPONSE_REFUSE);
		
	}
}
